home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / components / nsBrowserContentHandler.js < prev    next >
Text File  |  2006-05-08  |  22KB  |  686 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is the Mozilla Firefox browser.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Benjamin Smedberg <benjamin@smedbergs.us>
  18.  *
  19.  * Portions created by the Initial Developer are Copyright (C) 2004
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const nsISupports            = Components.interfaces.nsISupports;
  39.  
  40. const nsIBrowserDOMWindow    = Components.interfaces.nsIBrowserDOMWindow;
  41. const nsIBrowserHandler      = Components.interfaces.nsIBrowserHandler;
  42. const nsIBrowserHistory      = Components.interfaces.nsIBrowserHistory;
  43. const nsIChannel             = Components.interfaces.nsIChannel;
  44. const nsICommandLine         = Components.interfaces.nsICommandLine;
  45. const nsICommandLineHandler  = Components.interfaces.nsICommandLineHandler;
  46. const nsIContentHandler      = Components.interfaces.nsIContentHandler;
  47. const nsIDocShellTreeItem    = Components.interfaces.nsIDocShellTreeItem;
  48. const nsIDOMChromeWindow     = Components.interfaces.nsIDOMChromeWindow;
  49. const nsIDOMWindow           = Components.interfaces.nsIDOMWindow;
  50. const nsIFactory             = Components.interfaces.nsIFactory;
  51. const nsIFileURL             = Components.interfaces.nsIFileURL;
  52. const nsIHttpProtocolHandler = Components.interfaces.nsIHttpProtocolHandler;
  53. const nsIInterfaceRequestor  = Components.interfaces.nsIInterfaceRequestor;
  54. const nsIPrefBranch          = Components.interfaces.nsIPrefBranch;
  55. const nsIPrefLocalizedString = Components.interfaces.nsIPrefLocalizedString;
  56. const nsISupportsString      = Components.interfaces.nsISupportsString;
  57. const nsIURIFixup            = Components.interfaces.nsIURIFixup;
  58. const nsIWebNavigation       = Components.interfaces.nsIWebNavigation;
  59. const nsIWindowMediator      = Components.interfaces.nsIWindowMediator;
  60. const nsIWindowWatcher       = Components.interfaces.nsIWindowWatcher;
  61. const nsICategoryManager     = Components.interfaces.nsICategoryManager;
  62. const nsIWebNavigationInfo   = Components.interfaces.nsIWebNavigationInfo;
  63.  
  64. const NS_BINDING_ABORTED = 0x80020006;
  65. const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
  66. const NS_ERROR_ABORT = Components.results.NS_ERROR_ABORT;
  67.  
  68. function shouldLoadURI(aURI) {
  69.   if (aURI && !aURI.schemeIs("chrome"))
  70.     return true;
  71.  
  72.   dump("*** Preventing external load of chrome: URI into browser window\n");
  73.   dump("    Use -chrome <uri> instead\n");
  74.   return false;
  75. }
  76.  
  77. function resolveURIInternal(aCmdLine, aArgument) {
  78.   var uri = aCmdLine.resolveURI(aArgument);
  79.  
  80.   if (!(uri instanceof nsIFileURL)) {
  81.     return uri;
  82.   }
  83.  
  84.   try {
  85.     if (uri.file.exists())
  86.       return uri;
  87.   }
  88.   catch (e) {
  89.     Components.utils.reportError(e);
  90.   }
  91.  
  92.   // We have interpreted the argument as a relative file URI, but the file
  93.   // doesn't exist. Try URI fixup heuristics: see bug 290782.
  94.  
  95.   try {
  96.     var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
  97.                              .getService(nsIURIFixup);
  98.  
  99.     uri = urifixup.createFixupURI(aArgument, 0);
  100.   }
  101.   catch (e) {
  102.     Components.utils.reportError(e);
  103.   }
  104.  
  105.   return uri;
  106. }
  107.  
  108. function needHomepageOverride(prefb) {
  109.   var savedmstone;
  110.   try {
  111.     savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone");
  112.   }
  113.   catch (e) {
  114.   }
  115.  
  116.   if (savedmstone == "ignore")
  117.     return false;
  118.  
  119.   var mstone = Components.classes["@mozilla.org/network/protocol;1?name=http"]
  120.                          .getService(nsIHttpProtocolHandler).misc;
  121.  
  122.   if (mstone == savedmstone)
  123.     return false;
  124.  
  125.   prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
  126.   return true;
  127. }
  128.  
  129. function openWindow(parent, url, target, features, args) {
  130.   var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  131.                          .getService(nsIWindowWatcher);
  132.  
  133.   var argstring;
  134.   if (args) {
  135.     argstring = Components.classes["@mozilla.org/supports-string;1"]
  136.                             .createInstance(nsISupportsString);
  137.     argstring.data = args;
  138.   }
  139.   return wwatch.openWindow(parent, url, target, features, argstring);
  140. }
  141.  
  142. function openPreferences() {
  143.   var features = "chrome,titlebar,toolbar,centerscreen,dialog=no";
  144.   var url = "chrome://browser/content/preferences/preferences.xul";
  145.  
  146.   var win = getMostRecentWindow("Browser:Preferences");
  147.   if (win) {
  148.     win.focus();
  149.   } else {
  150.     openWindow(null, url, "_blank", features);
  151.   }
  152. }
  153.  
  154. function getMostRecentWindow(aType) {
  155.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  156.                      .getService(nsIWindowMediator);
  157.   return wm.getMostRecentWindow(aType);
  158. }
  159.  
  160. //@line 165 "/var/tmp/portage/mozilla-firefox-1.5.0.3/work/mozilla/browser/components/nsBrowserContentHandler.js"
  161.  
  162. // this returns the most recent non-popup browser window
  163. function getMostRecentBrowserWindow() {
  164.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  165.                      .getService(Components.interfaces.nsIWindowMediator);
  166.  
  167. //@line 172 "/var/tmp/portage/mozilla-firefox-1.5.0.3/work/mozilla/browser/components/nsBrowserContentHandler.js"
  168.   var win = wm.getMostRecentWindow("navigator:browser", true);
  169.  
  170.   // if we're lucky, this isn't a popup, and we can just return this
  171.   if (win && !win.toolbar.visible) {
  172.     var windowList = wm.getEnumerator("navigator:browser", true);
  173.     // this is oldest to newest, so this gets a bit ugly
  174.     while (windowList.hasMoreElements()) {
  175.       var nextWin = windowList.getNext();
  176.       if (nextWin.toolbar.visible)
  177.         win = nextWin;
  178.     }
  179.   }
  180. //@line 197 "/var/tmp/portage/mozilla-firefox-1.5.0.3/work/mozilla/browser/components/nsBrowserContentHandler.js"
  181.  
  182.   return win;
  183. }
  184.  
  185. var nsBrowserContentHandler = {
  186.   /* helper functions */
  187.  
  188.   mChromeURL : null,
  189.  
  190.   get chromeURL() {
  191.     if (this.mChromeURL) {
  192.       return this.mChromeURL;
  193.     }
  194.  
  195.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  196.                           .getService(nsIPrefBranch);
  197.     this.mChromeURL = prefb.getCharPref("browser.chromeURL");
  198.  
  199.     return this.mChromeURL;
  200.   },
  201.  
  202.   /* nsISupports */
  203.   QueryInterface : function bch_QI(iid) {
  204.     if (!iid.equals(nsISupports) &&
  205.         !iid.equals(nsICommandLineHandler) &&
  206.         !iid.equals(nsIBrowserHandler) &&
  207.         !iid.equals(nsIContentHandler) &&
  208.         !iid.equals(nsIFactory))
  209.       throw Components.errors.NS_ERROR_NO_INTERFACE;
  210.  
  211.     return this;
  212.   },
  213.  
  214.   /* nsICommandLineHandler */
  215.   handle : function bch_handle(cmdLine) {
  216.     if (cmdLine.handleFlag("browser", false)) {
  217.       openWindow(null, this.chromeURL, "_blank",
  218.                  "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  219.                  this.defaultArgs);
  220.       cmdLine.preventDefault = true;
  221.     }
  222.  
  223.     try {
  224.       var remoteCommand = cmdLine.handleFlagWithParam("remote", true);
  225.     }
  226.     catch (e) {
  227.       throw NS_ERROR_ABORT;
  228.     }
  229.  
  230.     if (remoteCommand != null) {
  231.       try {
  232.         var a = /^\s*(\w+)\(([^\)]*)\)\s*$/.exec(remoteCommand);
  233.         var remoteVerb = a[1].toLowerCase();
  234.         var remoteParams = [];
  235.         var sepIndex = a[2].lastIndexOf(",");
  236.         if (sepIndex == -1)
  237.           remoteParams[0] = a[2];
  238.         else {
  239.           remoteParams[0] = a[2].substring(0, sepIndex);
  240.           remoteParams[1] = a[2].substring(sepIndex + 1);
  241.         }
  242.  
  243.         switch (remoteVerb) {
  244.         case "openurl":
  245.         case "openfile":
  246.           // openURL(<url>)
  247.           // openURL(<url>,new-window)
  248.           // openURL(<url>,new-tab)
  249.  
  250.           var uri = resolveURIInternal(cmdLine, remoteParams[0]);
  251.  
  252.           var location = nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW;
  253.           if (/new-window/.test(remoteParams[1]))
  254.             location = nsIBrowserDOMWindow.OPEN_NEWWINDOW;
  255.           else if (/new-tab/.test(remoteParams[1]))
  256.             location = nsIBrowserDOMWindow.OPEN_NEWTAB;
  257.  
  258.           handURIToExistingBrowser(uri, location);
  259.           break;
  260.  
  261.         case "xfedocommand":
  262.           // xfeDoCommand(openBrowser)
  263.           if (remoteParams[0].toLowerCase() != "openbrowser")
  264.             throw NS_ERROR_ABORT;
  265.  
  266.           openWindow(null, this.chromeURL, "_blank",
  267.                      "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  268.                      this.defaultArgs);
  269.           break;
  270.  
  271.         default:
  272.           // Somebody sent us a remote command we don't know how to process:
  273.           // just abort.
  274.           throw NS_ERROR_ABORT;
  275.         }
  276.  
  277.         cmdLine.preventDefault = true;
  278.       }
  279.       catch (e) {
  280.         // If we had a -remote flag but failed to process it, throw
  281.         // NS_ERROR_ABORT so that the xremote code knows to return a failure
  282.         // back to the handling code.
  283.         throw NS_ERROR_ABORT;
  284.       }
  285.     }
  286.  
  287.     var uriparam;
  288.     try {
  289.       while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
  290.         var uri = resolveURIInternal(cmdLine, uriparam);
  291.         if (!shouldLoadURI(uri))
  292.           continue;
  293.         openWindow(null, this.chromeURL, "_blank",
  294.                    "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  295.                    uri.spec);
  296.         cmdLine.preventDefault = true;
  297.       }
  298.     }
  299.     catch (e) {
  300.       Components.utils.reportError(e);
  301.     }
  302.  
  303.     try {
  304.       while ((uriparam = cmdLine.handleFlagWithParam("new-tab", false))) {
  305.         var uri = resolveURIInternal(cmdLine, uriparam);
  306.         handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB);
  307.         cmdLine.preventDefault = true;
  308.       }
  309.     }
  310.     catch (e) {
  311.       Components.utils.reportError(e);
  312.     }
  313.  
  314.     var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
  315.     if (chromeParam) {
  316.  
  317.       // Handle the old preference dialog URL separately (bug 285416)
  318.       if (chromeParam == "chrome://browser/content/pref/pref.xul") {
  319.         openPreferences();
  320.       } else {
  321.         var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
  322.         openWindow(null, chromeParam, "_blank", features, "");
  323.       }
  324.  
  325.       cmdLine.preventDefault = true;
  326.     }
  327.     if (cmdLine.handleFlag("preferences", false)) {
  328.       openPreferences();
  329.       cmdLine.preventDefault = true;
  330.     }
  331.   },
  332.  
  333.   helpInfo : "  -browser            Open a browser window.\n",
  334.  
  335.   /* nsIBrowserHandler */
  336.  
  337.   get defaultArgs() {
  338.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  339.                           .getService(nsIPrefBranch);
  340.  
  341.     if (needHomepageOverride(prefb)) {
  342.       try {
  343.         return prefb.getComplexValue("startup.homepage_override_url",
  344.                                      nsIPrefLocalizedString).data;
  345.       }
  346.       catch (e) {
  347.       }
  348.     }
  349.  
  350.     try {
  351.       var choice = prefb.getIntPref("browser.startup.page");
  352.       if (choice == 1)
  353.         return this.startPage;
  354.  
  355.       if (choice == 2)
  356.         return Components.classes["@mozilla.org/browser/global-history;2"]
  357.                          .getService(nsIBrowserHistory).lastPageVisited;
  358.     }
  359.     catch (e) {
  360.     }
  361.  
  362.     return "about:blank";
  363.   },
  364.  
  365.   get startPage() {
  366.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  367.                           .getService(nsIPrefBranch);
  368.  
  369.     var uri = prefb.getComplexValue("browser.startup.homepage",
  370.                                     nsIPrefLocalizedString).data;
  371.  
  372.     if (!uri) {
  373.       prefb.clearUserPref("browser.startup.homepage");
  374.       uri = prefb.getComplexValue("browser.startup.homepage",
  375.                                   nsIPrefLocalizedString).data;
  376.     }
  377.                                 
  378.     var count;
  379.     try {
  380.       count = prefb.getIntPref("browser.startup.homepage.count");
  381.     }
  382.     catch (e) {
  383.       return uri;
  384.     }
  385.  
  386.     for (var i = 1; i < count; ++i) {
  387.       try {
  388.         var page = prefb.getComplexValue("browser.startup.homepage." + i,
  389.                                          nsIPrefLocalizedString).data;
  390.         uri += "\n" + page;
  391.       }
  392.       catch (e) {
  393.       }
  394.     }
  395.  
  396.     return uri;
  397.   },
  398.  
  399.   mFeatures : null,
  400.  
  401.   getFeatures : function bch_features(cmdLine) {
  402.     if (this.mFeatures === null) {
  403.       this.mFeatures = "";
  404.  
  405.       try {
  406.         var width = cmdLine.handleFlagWithParam("width", false);
  407.         var height = cmdLine.handleFlagWithParam("height", false);
  408.  
  409.         if (width)
  410.           this.mFeatures += ",width=" + width;
  411.         if (height)
  412.           this.mFeatures += ",height=" + height;
  413.       }
  414.       catch (e) {
  415.       }
  416.     }
  417.  
  418.     return this.mFeatures;
  419.   },
  420.  
  421.   /* nsIContentHandler */
  422.  
  423.   handleContent : function bch_handleContent(contentType, context, request) {
  424.     try {
  425.       var webNavInfo = Components.classes["@mozilla.org/webnavigation-info;1"]
  426.                                  .getService(nsIWebNavigationInfo);
  427.       if (!webNavInfo.isTypeSupported(contentType, null)) {
  428.         throw NS_ERROR_WONT_HANDLE_CONTENT;
  429.       }
  430.     } catch (e) {
  431.       throw NS_ERROR_WONT_HANDLE_CONTENT;
  432.     }
  433.  
  434.     var parentWin;
  435.     try {
  436.       parentWin = context.getInterface(nsIDOMWindow);
  437.     }
  438.     catch (e) {
  439.     }
  440.  
  441.     request.QueryInterface(nsIChannel);
  442.     
  443.     openWindow(parentWin, request.URI, "_blank", null, null);
  444.     request.cancel(NS_BINDING_ABORTED);
  445.   },
  446.  
  447.   /* nsIFactory */
  448.   createInstance: function bch_CI(outer, iid) {
  449.     if (outer != null)
  450.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  451.  
  452.     return this.QueryInterface(iid);
  453.   },
  454.     
  455.   lockFactory : function bch_lock(lock) {
  456.     /* no-op */
  457.   }
  458. };
  459.  
  460. const bch_contractID = "@mozilla.org/browser/clh;1";
  461. const bch_CID = Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}");
  462. const CONTRACTID_PREFIX = "@mozilla.org/uriloader/content-handler;1?type=";
  463.  
  464. function handURIToExistingBrowser(uri, location)
  465. {
  466.   if (!shouldLoadURI(uri))
  467.     return;
  468.  
  469.   var navWin = getMostRecentBrowserWindow();
  470.   if (!navWin) {
  471.     // if we couldn't load it in an existing window, open a new one
  472.     openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  473.                "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  474.                uri.spec);
  475.     return;
  476.   }
  477.  
  478.   var navNav = navWin.QueryInterface(nsIInterfaceRequestor)
  479.                      .getInterface(nsIWebNavigation);
  480.   var rootItem = navNav.QueryInterface(nsIDocShellTreeItem).rootTreeItem;
  481.   var rootWin = rootItem.QueryInterface(nsIInterfaceRequestor)
  482.                         .getInterface(nsIDOMWindow);
  483.   var bwin = rootWin.QueryInterface(nsIDOMChromeWindow).browserDOMWindow;
  484.   bwin.openURI(uri, null, location,
  485.                nsIBrowserDOMWindow.OPEN_EXTERNAL);
  486. }
  487.  
  488.  
  489. var nsDefaultCommandLineHandler = {
  490.   /* nsISupports */
  491.   QueryInterface : function dch_QI(iid) {
  492.     if (!iid.equals(nsISupports) &&
  493.         !iid.equals(nsICommandLineHandler) &&
  494.         !iid.equals(nsIFactory))
  495.       throw Components.errors.NS_ERROR_NO_INTERFACE;
  496.  
  497.     return this;
  498.   },
  499.  
  500.   /* nsICommandLineHandler */
  501.   handle : function dch_handle(cmdLine) {
  502.     var urilist = [];
  503.  
  504.     try {
  505.       var ar;
  506.       while ((ar = cmdLine.handleFlagWithParam("url", false))) {
  507.         urilist.push(resolveURIInternal(cmdLine, ar));
  508.       }
  509.     }
  510.     catch (e) {
  511.       Components.utils.reportError(e);
  512.     }
  513.  
  514.     var count = cmdLine.length;
  515.  
  516.     for (var i = 0; i < count; ++i) {
  517.       var curarg = cmdLine.getArgument(i);
  518.       if (curarg.match(/^-/)) {
  519.         Components.utils.reportError("Warning: unrecognized command line flag " + curarg + "\n");
  520.         // To emulate the pre-nsICommandLine behavior, we ignore
  521.         // the argument after an unrecognized flag.
  522.         ++i;
  523.       } else {
  524.         try {
  525.           urilist.push(resolveURIInternal(cmdLine, curarg));
  526.         }
  527.         catch (e) {
  528.           Components.utils.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
  529.         }
  530.       }
  531.     }
  532.  
  533.     if (urilist.length) {
  534.       if (cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
  535.           urilist.length == 1) {
  536.         // Try to find an existing window and load our URI into the
  537.         // current tab, new tab, or new window as prefs determine.
  538.         try {
  539.           handURIToExistingBrowser(urilist[0], nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW);
  540.           return;
  541.         }
  542.         catch (e) {
  543.         }
  544.       }
  545.  
  546.       var speclist = [];
  547.       for (var uri in urilist) {
  548.         if (shouldLoadURI(urilist[uri]))
  549.           speclist.push(urilist[uri].spec);
  550.       }
  551.  
  552.       if (speclist.length) {
  553.         openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  554.                    "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  555.                    speclist.join("|"));
  556.       }
  557.  
  558.     }
  559.     else if (!cmdLine.preventDefault) {
  560.       openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  561.                  "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  562.                  nsBrowserContentHandler.defaultArgs);
  563.     }
  564.   },
  565.  
  566.   // XXX localize me... how?
  567.   helpInfo : "Usage: firefox [-flags] [<url>]\n",
  568.  
  569.   /* nsIFactory */
  570.   createInstance: function dch_CI(outer, iid) {
  571.     if (outer != null)
  572.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  573.  
  574.     return this.QueryInterface(iid);
  575.   },
  576.     
  577.   lockFactory : function dch_lock(lock) {
  578.     /* no-op */
  579.   }
  580. };
  581.  
  582. const dch_contractID = "@mozilla.org/browser/final-clh;1";
  583. const dch_CID = Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}");
  584.  
  585. var Module = {
  586.   /* nsISupports */
  587.   QueryInterface: function mod_QI(iid) {
  588.     if (iid.equals(Components.interfaces.nsIModule) ||
  589.         iid.equals(Components.interfaces.nsISupports))
  590.       return this;
  591.  
  592.     throw Components.results.NS_ERROR_NO_INTERFACE;
  593.   },
  594.  
  595.   /* nsIModule */
  596.   getClassObject: function mod_getco(compMgr, cid, iid) {
  597.     if (cid.equals(bch_CID))
  598.       return nsBrowserContentHandler.QueryInterface(iid);
  599.  
  600.     if (cid.equals(dch_CID))
  601.       return nsDefaultCommandLineHandler.QueryInterface(iid);
  602.  
  603.     throw Components.results.NS_ERROR_NO_INTERFACE;
  604.   },
  605.     
  606.   registerSelf: function mod_regself(compMgr, fileSpec, location, type) {
  607.     var compReg =
  608.       compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
  609.  
  610.     compReg.registerFactoryLocation( bch_CID,
  611.                                      "nsBrowserContentHandler",
  612.                                      bch_contractID,
  613.                                      fileSpec,
  614.                                      location,
  615.                                      type );
  616.     compReg.registerFactoryLocation( dch_CID,
  617.                                      "nsDefaultCommandLineHandler",
  618.                                      dch_contractID,
  619.                                      fileSpec,
  620.                                      location,
  621.                                      type );
  622.  
  623.     function registerType(contentType) {
  624.       compReg.registerFactoryLocation( bch_CID,
  625.                        "Browser Cmdline Handler",
  626.                        CONTRACTID_PREFIX + contentType,
  627.                        fileSpec,
  628.                        location,
  629.                        type );
  630.     }
  631.  
  632.     registerType("text/html");
  633.     registerType("application/vnd.mozilla.xul+xml");
  634. //@line 651 "/var/tmp/portage/mozilla-firefox-1.5.0.3/work/mozilla/browser/components/nsBrowserContentHandler.js"
  635.     registerType("image/svg+xml");
  636. //@line 653 "/var/tmp/portage/mozilla-firefox-1.5.0.3/work/mozilla/browser/components/nsBrowserContentHandler.js"
  637.     registerType("text/rdf");
  638.     registerType("text/xml");
  639.     registerType("application/xhtml+xml");
  640.     registerType("text/css");
  641.     registerType("text/plain");
  642.     registerType("image/gif");
  643.     registerType("image/jpeg");
  644.     registerType("image/jpg");
  645.     registerType("image/png");
  646.     registerType("image/bmp");
  647.     registerType("image/x-icon");
  648.     registerType("image/vnd.microsoft.icon");
  649.     registerType("image/x-xbitmap");
  650.     registerType("application/http-index-format");
  651.  
  652.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  653.                            .getService(nsICategoryManager);
  654.  
  655.     catMan.addCategoryEntry("command-line-handler",
  656.                             "m-browser",
  657.                             bch_contractID, true, true);
  658.     catMan.addCategoryEntry("command-line-handler",
  659.                             "x-default",
  660.                             dch_contractID, true, true);
  661.   },
  662.     
  663.   unregisterSelf : function mod_unregself(compMgr, location, type) {
  664.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  665.     compReg.unregisterFactoryLocation(bch_CID, location);
  666.     compReg.unregisterFactoryLocation(dch_CID, location);
  667.  
  668.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  669.                            .getService(nsICategoryManager);
  670.  
  671.     catMan.deleteCategoryEntry("command-line-handler",
  672.                                "m-browser", true);
  673.     catMan.deleteCategoryEntry("command-line-handler",
  674.                                "x-default", true);
  675.   },
  676.  
  677.   canUnload: function(compMgr) {
  678.     return true;
  679.   }
  680. };
  681.  
  682. // NSGetModule: Return the nsIModule object.
  683. function NSGetModule(compMgr, fileSpec) {
  684.   return Module;
  685. }
  686.